# app/models/log.py
from sqlalchemy import Column, Integer, String, DateTime
from app.database import Base
from datetime import datetime, timezone, timedelta

# 定义东八区时区
china_tz = timezone(timedelta(hours=8))

class Log(Base):
    __tablename__ = "logs"

    id = Column(Integer, primary_key=True, index=True)
    action = Column(String(50), index=True)  # 添加索引提高查询效率
    details = Column(String(500))  # 日志详情
    created_at = Column(DateTime, default=lambda: datetime.now(china_tz), nullable=False)  # 自动填充当前时间

    # 可选的repr方法，便于调试
    def __repr__(self):
        return f"<Test id={self.id} action='{self.action}' details={self.details}>"
